package com.kedacom.freedomLabel.label;

import com.kedacom.freedomLabel.base.UserCache;
import com.kedacom.freedomLabel.label.annotation.TemplateName;
import com.kedacom.freedomLabel.model.bean.Business;
import com.kedacom.freedomLabel.model.bean.Template;
import com.kedacom.freedomLabel.model.db.Converters;

/**
 * @author licheng
 * @since 2019/12/6 15:03
 */
public class Client {

    public static void main(String[] args) {

        // prepare columnNames
        UserCache.customColumnNames = Converters.sDefaultColumnNames;

        // prepare UserCache
        UserCache.companyName = "This is company name";
        UserCache.companyTel = "0512-12345678";
        UserCache.companyFax = "0512-12345678";
        UserCache.companyAddress = "This is company address";

        // prepare data to print
        Business data = new Business();
        data.category = "This is title";
//        data.item1 = new Item("item1-value");
//        data.item2 = new Item("item2-value");
//        data.item3 = new Item("item3-value");
//        data.item4 = new Item("item4-value");
//        data.item5 = new Item("item5-value");
//        data.item6 = new Item("item6-value");

        // prepare company information
        TemplateManager.CompanyPosition companyPosition = new TemplateManager.CompanyPosition();
        companyPosition.name = new Template.Position(11, 11);
        companyPosition.contactNumber = new Template.Position(12, 12);
        companyPosition.faxNumber = new Template.Position(13, 13);
        companyPosition.address = new Template.Position(14, 14);

        // prepare order information
        TemplateManager.OrderPosition orderPosition = new TemplateManager.OrderPosition();
        orderPosition.batch = new Template.Position(8, 8);
        orderPosition.serial = new Template.Position(9, 9);
        orderPosition.time = new Template.Position(10, 10);

        // init using label-template
        Template template = new TemplateManager.Builder(60, 40)
                .addTitle(0, 0)
                .addQR(1, 1)
                .addID1(2, 2)
                .addID2(3, 3)
                .addID3(4, 4)
                .addID4(5, 5)
                .addID5(6, 6)
                .addID6(7, 7)
                .addCompanyInformation(companyPosition)
                .addOrderInformation(orderPosition)
                .build(TemplateName.LABEL_1);

        TemplateManager manager = TemplateManager.getInstance();
        Label<Business> businessLabel = manager.bindLabel(template, data);
        System.out.println(new String(businessLabel.encodeCommand()));

        // result
        /*
            DIRECTION 1,0
            REFERENCE 0,0
            SET TEAR 1
            CLS
            SIZE 60 mm,40 mm
            TEXT 0,0,"TSS24.BF2",0,2,2,"This is title"
            TEXT 2,2,"TSS24.BF2",0,1,1,"ID1:item1-value"
            TEXT 3,3,"TSS24.BF2",0,1,1,"ID2:item2-value"
            TEXT 4,4,"TSS24.BF2",0,1,1,"ID3:item3-value"
            TEXT 5,5,"TSS24.BF2",0,1,1,"ID4:item4-value"
            TEXT 6,6,"TSS24.BF2",0,1,1,"ID5:item5-value"
            TEXT 7,7,"TSS24.BF2",0,1,1,"ID6:item6-value"
            TEXT 11,11,"TSS24.BF2",0,1,1,"companyName:This is company name"
            TEXT 12,12,"TSS24.BF2",0,1,1,"companyContactNumber:0512-12345678"
            TEXT 13,13,"TSS24.BF2",0,1,1,"companyFaxNumber:0512-12345678"
            TEXT 14,14,"TSS24.BF2",0,1,1,"companyAddress:This is company address"
            SOUND 1,100
            PRINT 1,1
        */
    }
}